package com.lxmes.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.lxmes.system.domain.MhColumnType;
import com.lxmes.system.service.IMhColumnTypeService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 栏目类型Controller
 * 
 * @author zhangzhiyu
 * @date 2023-06-07
 */
@Api(tags = "栏目类型")    
@RestController
@RequestMapping("/system/mhColumnType")
public class MhColumnTypeController extends BaseController
{
    @Autowired
    private IMhColumnTypeService mhColumnTypeService;

    /**
     * 查询栏目类型列表
     */
    @ApiOperation("查询栏目类型列表")
    @PreAuthorize("@ss.hasPermi('system:mhColumnType:list')")
    @GetMapping("/list")
    public TableDataInfo list(MhColumnType mhColumnType)
    {
        startPage();
        List<MhColumnType> list = mhColumnTypeService.selectMhColumnTypeList(mhColumnType);
        return getDataTable(list);
    }
    @GetMapping("/listAll")
    public AjaxResult listAll(MhColumnType mhColumnType)
    {
        mhColumnType.setIsEnabled("1");
        List<MhColumnType> list = mhColumnTypeService.selectMhColumnTypeList(mhColumnType);
        return AjaxResult.success(list);
    }

    /**
     * 导出栏目类型列表
     */
    @ApiOperation("导出栏目类型列表")
    @PreAuthorize("@ss.hasPermi('system:mhColumnType:export')")
    @Log(title = "栏目类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MhColumnType mhColumnType)
    {
        List<MhColumnType> list = mhColumnTypeService.selectMhColumnTypeList(mhColumnType);
        ExcelUtil<MhColumnType> util = new ExcelUtil<MhColumnType>(MhColumnType.class);
        util.exportExcel(response, list, "栏目类型数据");
    }

    /**
     * 获取栏目类型详细信息
     */
    @ApiOperation("获取栏目类型详细信息")
    @PreAuthorize("@ss.hasPermi('system:mhColumnType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(mhColumnTypeService.selectMhColumnTypeById(id));
    }

    /**
     * 新增栏目类型
     */
    @ApiOperation("新增栏目类型")
    @PreAuthorize("@ss.hasPermi('system:mhColumnType:add')")
    @Log(title = "栏目类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MhColumnType mhColumnType)
    {
        return toAjax(mhColumnTypeService.insertMhColumnType(mhColumnType));
    }

    /**
     * 修改栏目类型
     */
    @ApiOperation("修改栏目类型")
    @PreAuthorize("@ss.hasPermi('system:mhColumnType:edit')")
    @Log(title = "栏目类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MhColumnType mhColumnType)
    {
        return toAjax(mhColumnTypeService.updateMhColumnType(mhColumnType));
    }

    /**
     * 删除栏目类型
     */
    @ApiOperation("删除栏目类型")
    @PreAuthorize("@ss.hasPermi('system:mhColumnType:remove')")
    @Log(title = "栏目类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mhColumnTypeService.deleteMhColumnTypeByIds(ids));
    }
    /**
     * 导入栏目类型
     */
    @Log(title = "栏目类型", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<MhColumnType> util = new ExcelUtil<>(MhColumnType.class);
        List<MhColumnType> mhColumnTypeList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = mhColumnTypeService.imporIteminfo(mhColumnTypeList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    // 下载模板
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<MhColumnType> util = new ExcelUtil<>(MhColumnType.class);
        util.importTemplateExcel(response,"栏目类型");
    }
}
